package com.soul.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> implements Serializable {
    /**
     *  总记录数
     */
    private Long counts = 0L;
    /**
     *  页大小(当前页条数)
     */
    private Long pagesize;
    /**
     *  总页数
     */
    private Long pages = 0L;
    /**
     *  当前页码
     */
    private Long page;
    /**
     *  列表
     */
    private List<T> items = Collections.emptyList();

    /**
     *
     * @param page 当前页
     * @param pagesize 每页条数
     * @param counts 总条数
     * @param list 集合
     */
    public PageResult(Long page,Long pagesize,Long counts,List<T> list) {
        this.page = page;
        this.pagesize = pagesize;
        this.items = list;
        this.counts = counts;
        this.pages = counts % pagesize == 0 ? counts / pagesize : counts / pagesize + 1;
    }
}